package cn.wolfcode.crm.domain;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
public class SystemDictionaryItem {
    private Long id;

    private SystemDictionary parent;

    private String title;

    private Integer sequence;

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);

        map.put("parentId", parent.getId());
        map.put("parentTitle", parent.getTitle());

        ObjectMapper mapper = new ObjectMapper();
        //将map转换为json格式字符串
        try {
            String json = mapper.writeValueAsString(map);
            return json;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }


}